package xyz.mumuwei.youthcourseserver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.ApplicationContext;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author mumuwei
 */
@Slf4j
@SpringBootApplication
public class YouthCourseServerApplication {

    protected static ApplicationContext ctx;

    public static void main(String[] args) {
        ctx = SpringApplication.run(YouthCourseServerApplication.class, args);
        try {
            String host = InetAddress.getLocalHost().getHostAddress();
            TomcatServletWebServerFactory tomcatServletWebServerFactory = (TomcatServletWebServerFactory) ctx
                    .getBean("tomcatServletWebServerFactory");
            int port = tomcatServletWebServerFactory.getPort();
            String contextPath = tomcatServletWebServerFactory.getContextPath();
            log.info(">>>启动成功,项目根路径: http://" + host + ":" + port + contextPath + "/");
            log.info(">>>启动成功,测试路径: http://" + host + ":" + port + contextPath + "/test");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
